package com.logistics.controller;

import com.logistics.common.Result;
import com.logistics.entity.WarehouseStorage;
import com.logistics.service.WarehouseStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/storage")
public class WarehouseStorageController {
    @Autowired
    private WarehouseStorageService warehouseStorageService;

    @PostMapping
    public Result<Void> create(@RequestBody WarehouseStorage storage) {
        warehouseStorageService.create(storage);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<WarehouseStorage> getById(@PathVariable Long id) {
        WarehouseStorage storage = warehouseStorageService.getById(id);
        return Result.success(storage);
    }

    @GetMapping("/warehouse/{warehouseId}")
    public Result<List<WarehouseStorage>> listByWarehouseId(@PathVariable Long warehouseId) {
        List<WarehouseStorage> storages = warehouseStorageService.listByWarehouseId(warehouseId);
        return Result.success(storages);
    }

    @GetMapping("/order/{orderNo}")
    public Result<List<WarehouseStorage>> listByOrderNo(@PathVariable String orderNo) {
        List<WarehouseStorage> storages = warehouseStorageService.listByOrderNo(orderNo);
        return Result.success(storages);
    }

    @GetMapping("/list")
    public Result<List<WarehouseStorage>> list() {
        List<WarehouseStorage> storages = warehouseStorageService.list();
        return Result.success(storages);
    }

    @GetMapping("/search")
    public Result<List<WarehouseStorage>> search(
            @RequestParam(required = false) String orderNo,
            @RequestParam(required = false) Long warehouseId,
            @RequestParam(required = false) String status) {
        return warehouseStorageService.search(orderNo, warehouseId, status);
    }

    @PutMapping("/{id}/status/{status}")
    public Result<Void> updateStatus(@PathVariable Long id, @PathVariable String status) {
        warehouseStorageService.updateStatus(id, status);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        warehouseStorageService.delete(id);
        return Result.success();
    }
} 